
// 需要鉴权的路由
const no_auth = ['ping','user/login','user/register','user/logout','user/sendcode','user/flush']
// url
const base_url = 'http://117.72.38.46:8080/'
// const base_url = 'http://127.0.0.1:8080/'
// const base_url = 'http://bd4b0c7.r3.cpolar.cn/'
uni.addInterceptor("request",{
	invoke(args) {
		//无权限则redirect 到index
		console.log("发送请求")
		console.log(args)
		//需要鉴权
		if(!no_auth.includes(args.url)){
			uni.getStorage({
				key:"token",
				success:(res)=> {
					console.log("获取 request tk成功")
					args.header = { 'Authorization': res.data }
					// args.url = args.url+"Authorization="+res.data
				},
				fail(res) {
					console.log("获取 request tk失败")
					uni.reLaunch({
						url:"/pages/login/index"
					})
				}
			})
		}
		args.url = base_url + args.url
		console.log("请求总体")
		console.log(args)
	},
	success(res) {
		console.log("请求之后")
		console.log(res)
	}
})
uni.addInterceptor("uploadFile",{
	invoke(args) {
		console.log("发送请求")
		console.log(args)
		//无权限则redirect 到index
		//需要鉴权
		if(!no_auth.includes(args.url)){
			console.log("uploadFile 鉴权")
			uni.getStorage({
				key:"token",
				success:(res)=> {
					args.header = { 'Authorization': res.data }
					// args.url = args.url+"Authorization="+res.data
				},
				fail(res) {
					uni.reLaunch({
						url:"/pages/login/index"
					})
				}
			})
		}
		args.url = base_url + args.url
		console.log("请求总体")
		console.log(args)
	},
	success(res) {
	}
})